const Service = require('egg').Service;
const crypto = require("crypto");  //  引入加密方法

class UserService extends Service {
  async index({username}) {
    const { ctx,app } = this;
   
    const sql = `select username from user where username='${username}'`;
    return await app.mysql.query(sql);
  }
  // 登录
  async userLogin({username, password}) {
    const { app } = this;
    password = crypto.createHash('md5').update(password).digest('hex');  //  对密码进行加密
   return await app.mysql.get("user",{
       username,
       password
   })
  }
  async userRegisty({username, password}) {
    const { app } = this;
     password = crypto.createHash('md5').update(password).digest('hex');   //  对密码进行加密
    return await app.mysql.query(`insert into user (username, password) values ('${username}','${password}')`)
  }
}

module.exports = UserService;